import entity.Employ;
import entity.Users;
import service.EmployService;
import service.EmployServiceImpl;
import service.UserService;
import service.UserServiceImpl;
import util.Oprea;

import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class Test {
    Scanner input=new Scanner(System.in);
    SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd");
    Date dates=null;
    public static void main(String[] args) {
        Test test=new Test();
        test.menus();

    }
    //一级菜单
    public void menus(){
        UserService userService=new UserServiceImpl();
        int count=0;
        do{
            System.out.println("1.登入");
            System.out.println("2.注册");
            System.out.println("3.退出");
            System.out.println("请选择:");
            switch (input.nextInt()) {
                case 1:
                    //登入
                    System.out.println("请输入用户名:");
                    String names = input.next();
                    System.out.println("请输入密码:");
                    String paswards = input.next();
                    if (userService.checkLogin(names, paswards)) {
                        menu();
                    } else {
                        System.out.println("用户名或密码错误");
                        count++;
                        if(count==3){
                            System.exit(1);
                        }
                    }
                    break;
                case 2:
                    //注册
                    System.out.println("请输入用户名:");
                    String name=input.next();
                    System.out.println("请输入密码:");
                    String pasward=input.next();
                    Users users=new Users(name,pasward);
                    if(userService.addUser(users)){
                        System.out.println("注册成功");
                    }
                    break;
                case 3:
                    System.out.println("欢迎下次光临");
                    System.exit(1);
                    default:
                        System.out.println("请重新选择:");
            }
        }while (true);
    }
    //二级菜单
    public void menu(){
        EmployService employService=new EmployServiceImpl();
        do{
            System.out.println("1.查询员工信息");
            System.out.println("2.根据编号查看员工信息");
            System.out.println("3.添加员工信息");
            System.out.println("4.修改员工工资");
            System.out.println("5.删除员工信息");
            System.out.println("0.退出");
            System.out.println("请选择");
            switch (input.nextInt()){
                case 1:
                    employService.show();
                    break;
                case 2:
                    System.out.println("请输入员工编号");
                    int id=input.nextInt();
                    employService.showByID(id);
                    break;
                case 3:
                    System.out.println("请输入员工编号:");
                    int ids=input.nextInt();
                    System.out.println("请输入员工姓名:");
                    String names=input.next();
                    System.out.println("请输入员工职位:");
                    String job=input.next();
                    System.out.println("请输入员工入职时间:");
                    String date=input.next();
                    System.out.println("请输入员工工资:");
                    double money=input.nextDouble();
                    try {
                        dates=simpleDateFormat.parse(date);
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                    Employ employ=new Employ(ids,names,job,dates,money);

                    if(employService.addEmp(employ)){
                        System.out.println("添加成功");
                    }else {
                        System.out.println("添加未成功");
                    }
                    break;
                case 4:
                    System.out.println("请输入员工编号:");
                    int id1=input.nextInt();
                    System.out.println("请输入员工工资:");
                    double moneys=input.nextDouble();
                    Employ employ1=new Employ();
                    employ1.setMoney(moneys);
                    employService.updateEmp(employ1);
                    break;
                case 5:
                    System.out.println("请输入员工编号:");
                    int id3=input.nextInt();
                    employService.deleteEmp(id3);
                    break;
                case 0:
                    System.exit(1);
                    default:
                        System.out.println("请重新输入");
            }
        }while (true);
    }
}
